#include <iostream>
#include <algorithm>

using namespace std;

const int N = 310;

struct Point
{
	int pos, ch, sum;
	
	bool operator< (const Point &t)const
	{
		if(sum != t.sum) return t.sum < sum;
		else if (ch != t.ch) return t.ch < ch;
		else return pos < t.pos; 
	}
}person[N];

int n;

int main()
{
	cin >> n;
	
	for (int i = 1; i <= n; i ++ )
	{
		int a, b, c;
		cin >> a >> b >> c;
		
		int sum = a + b + c;
		person[i - 1] = {i, a, sum};
	}
	
	sort(person, person + n);
	
	for (int i = 0; i < 5; i ++ ) cout << person[i].pos << ' ' << person[i].sum << endl;
	
	return 0;
}
